<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class meta_data_controller extends admin_controller
{
    // Get list
    public function __construct()
    {
        parent::__construct();
        $this->page_title = 'Meta data';
        $this->table_name = 'meta_data';
        $this->route_name = 'meta-data';
        $this->business_model = $this->meta_data_model;
    }

    public function get_post_data()
    {
        $post_data = array(
            'uri' => $this->input->post('uri'),
            'site_title' => $this->input->post('site_title'),
            'meta_description' => $this->input->post('meta_description'),
            'note' => $this->input->post('note'),
            'modified_date' => time()
        );
        return $post_data;
    }

    public function get_list()
    {
        $list = array();
        $items = $this->business_model->get_elements();
        foreach($items as $item)
        {
            $actions = array();
            $actions[] = array(
                'text' => 'Sửa',
                'href' => base_url(). $this->base_admin_url .$this->route_name.'/update/'.$item->id
            );
            $list[] = array(
                'can_delete' => $item->id,
                'uri' => $item->uri,
                'site_title' => $item->site_title,
                'meta_description' => $item->meta_description,
                'note' => $item->note,
                'actions' => $actions
            );
        }
        return $list;
    }

    public function get_header_list()
    {
        $list = array();
        $list[] = 'Đường dẫn';
        $list[] = 'Tiêu đề web';
        $list[] = 'Mô tả web';
        $list[] = 'Ghi chú';
        $list[] = 'Công việc';
        return $list;
    }

    public function get_fields($id)
    {
        if($id == -1)
        {
            $model->uri = '';
            $model->site_title = '';
            $model->meta_description ='';
            $model->note = '';
        }
        else
        {
            $model = $this->business_model->get_element_by_id($id);
        }
        $fields = array();
        $fields[] = array(
            'text' => 'Đường dẫn (không bao gồm tên miền)',
            'name' => 'uri',
            'value' => $model->uri,
            'type' => 'text'
        );
        $fields[] = array(
            'text' => 'Tiêu đề web',
            'name' => 'site_title',
            'value' => $model->site_title,
            'type' => 'text'
        );
        $fields[] = array(
            'text' => 'Mô tả web',
            'name' => 'meta_description',
            'value' => $model->meta_description,
            'type' => 'text'
        );
        $fields[] = array(
            'text' => 'Ghi chú',
            'name' => 'note',
            'value' => $model->note,
            'type' => 'text'
        );

        return $fields;
    }
    
}